<?php
$timestamp = time();
$flush="864000";
$flush1="864000";
function open($file,$type=''){
/*
读取远程页面
*/
        global $fromurl,$referer;
        $cachename=$file;
                if($type){
                        $file=$fromurl.'/'.$type.'/'.$file;
                }else{
                        $file=$fromurl.$file;
                }
                        if($open=file($file)){
                                        $count=count($open);
                                        for($i=0;$i<$count;$i++){
                                                $theget.=$open[$i];
                                        }
                                }else{
                                        die('请求过多，超时，请刷新');
                                }
        return $theget;
}

function cut($file,$from,$end){
        $message=explode($from,$file);
        $message=explode($end,$message[1]);
return        $message[0];
}

function path($path) {  
  if(!@dir($path)){  
  mkdir($path,0777);  
  }  
}   

function curl($openurl){
	global $isfun;
	if($isfun=="curl"){
	$ch = curl_init($openurl);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$file = curl_exec($ch);
	curl_close($ch);
	}
	elseif($isfun=="fopen"){
		$file=open($openurl);
	}
	else{ echo "<script>alert('你的空间不支持本程序，谢谢使用');window.close();</script>";}
	return $file;
}

function mtime($cachename){
//判断文件修改时间
		if(file_exists($cachename)){
		$lastflesh=@filemtime($cachename);
		return $lastflesh;
		}
}


Function cachefile1($cachename)
{ global $timestamp,$flush;
//判断文件是否存在开始
if(!file_exists($cachename)){
$mystr="";
}else{
//判读文件时间开始
$lastflesh=@filemtime($cachename);
if($lastflesh + ($flush * 60) < $timestamp ){
$mystr="";	
}
else{
//读取文件开始
//if($open=file($cachename))
//$fp2 = @fopen($cachefilename,"w")
$mystr	= "111";
		}
//读取文件结束

//判读文件时间结束
}
//判断文件是否存在结束
return $mystr;
}

Function readtpl($cachename)
{ global $timestamp,$flush;
//判断文件是否存在开始
if(!file_exists($cachename)){
$mystr="";
}
else{
//读取文件开始
if($open=file($cachename))
$fp2 = @fopen($cachename,"r");
@flock($fp2, 2);
$fup = fread($fp2,filesize($cachename)); 
fclose($fp2);
$mystr	= $fup;
		}
//读取文件结束

//判读文件时间结束

//判断文件是否存在结束
return $mystr;
}


Function cachexml($cachename)
{ global $timestamp,$flush1;
//判断文件是否存在开始
if(!file_exists($cachename)){
$mystr="";
}else{
//判读文件时间开始
$lastflesh=@filemtime($cachename);
if($lastflesh + ($flush1 * 60) < $timestamp ){
$mystr="";	
}else{
//读取文件开始
//if($open=file($cachename))
//$fp2 = @fopen($cachefilename,"w")
$xml= new SimplexmlElement($cachename,NULL,TRUE);}
if (!$xml) {
	$mystr="";
}
else{
	$mystr="1";
//读取文件结束
}
//判读文件时间结束
}
//判断文件是否存在结束
return $mystr;
}


?>